package net.mgsx.product.t2m.modisco.tools;

import net.mgsx.product.t2m.modisco.ModiscoTestCase;

import org.eclipse.gmt.modisco.java.ClassDeclaration;
import org.eclipse.gmt.modisco.java.CompilationUnit;
import org.eclipse.gmt.modisco.java.ImportDeclaration;
import org.eclipse.gmt.modisco.java.Model;
import org.eclipse.gmt.modisco.java.emf.JavaFactory;
import org.junit.Assert;
import org.junit.Test;

public class ModiscoUtilsTestCase extends ModiscoTestCase {

	@Test
	public void testGetOwnerNominal() throws Exception{
		Model model = JavaFactory.eINSTANCE.createModel();
		CompilationUnit cu = JavaFactory.eINSTANCE.createCompilationUnit();
		ImportDeclaration id = JavaFactory.eINSTANCE.createImportDeclaration();
		cu.getImports().add(id);
		model.getCompilationUnits().add(cu);
		Model result = ModiscoUtils.getOwner(id, Model.class);
		Assert.assertEquals(model, result);
	}
	@Test
	public void testGetOwnerOnSelf() throws Exception{
		Model model = JavaFactory.eINSTANCE.createModel();
		CompilationUnit cu = JavaFactory.eINSTANCE.createCompilationUnit();
		model.getCompilationUnits().add(cu);
		CompilationUnit result = ModiscoUtils.getOwner(cu, CompilationUnit.class);
		Assert.assertEquals(cu, result);
	}
	@Test
	public void testGetOwnerNotExists() throws Exception{
		Model model = JavaFactory.eINSTANCE.createModel();
		CompilationUnit cu = JavaFactory.eINSTANCE.createCompilationUnit();
		model.getCompilationUnits().add(cu);
		ClassDeclaration result = ModiscoUtils.getOwner(cu, ClassDeclaration.class);
		Assert.assertNull(result);
	}
	@Test
	public void testGetOwnerNull() throws Exception{
		ClassDeclaration result = ModiscoUtils.getOwner(null, ClassDeclaration.class);
		Assert.assertNull(result);
	}
}
